package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.TbTrack;
import com.ruoyi.system.service.ITbTrackService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 历史轨迹Controller
 * 
 * @author ruoyi
 * @date 2023-06-29
 */
@RestController
@RequestMapping("/track")
public class TbTrackController extends BaseController
{
    @Autowired
    private ITbTrackService tbTrackService;

    /**
     * 查询历史轨迹列表
     */
    @RequiresPermissions("system:track:list")
    @GetMapping("/list")
    public TableDataInfo list(TbTrack tbTrack)
    {
        startPage();
        List<TbTrack> list = tbTrackService.selectTbTrackList(tbTrack);
        return getDataTable(list);
    }

    /**
     * 导出历史轨迹列表
     */
    @RequiresPermissions("system:track:export")
    @Log(title = "历史轨迹", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbTrack tbTrack)
    {
        List<TbTrack> list = tbTrackService.selectTbTrackList(tbTrack);
        ExcelUtil<TbTrack> util = new ExcelUtil<TbTrack>(TbTrack.class);
        util.exportExcel(response, list, "历史轨迹数据");
    }

    /**
     * 获取历史轨迹详细信息
     */
    @RequiresPermissions("system:track:query")
    @GetMapping(value = "/{trackId}")
    public AjaxResult getInfo(@PathVariable("trackId") Long trackId)
    {
        return success(tbTrackService.selectTbTrackByTrackId(trackId));
    }

    /**
     * 新增历史轨迹
     */
    @RequiresPermissions("system:track:add")
    @Log(title = "历史轨迹", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbTrack tbTrack)
    {
        return toAjax(tbTrackService.insertTbTrack(tbTrack));
    }

    /**
     * 修改历史轨迹
     */
    @RequiresPermissions("system:track:edit")
    @Log(title = "历史轨迹", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbTrack tbTrack)
    {
        return toAjax(tbTrackService.updateTbTrack(tbTrack));
    }

    /**
     * 删除历史轨迹
     */
    @RequiresPermissions("system:track:remove")
    @Log(title = "历史轨迹", businessType = BusinessType.DELETE)
	@DeleteMapping("/{trackIds}")
    public AjaxResult remove(@PathVariable Long[] trackIds)
    {
        return toAjax(tbTrackService.deleteTbTrackByTrackIds(trackIds));
    }
}
